package com.dong.adapter;

import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.List;

import com.dong.yi18health.R;
import com.squareup.picasso.Picasso;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import fragment.News2;

public class Adapter_list1 extends BaseAdapter{
	List<News2> data;
	Context context;
	public Adapter_list1(List<News2> data,Context context) {
		this.data = data;
		this.context=context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return data.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		ViewHolder vh;
		if(arg1==null){
			vh=new ViewHolder();
			arg1=View.inflate(context, R.layout.item1, null);
			vh.titel=(TextView) arg1.findViewById(R.id.item1_title);
			vh.readtime=(TextView) arg1.findViewById(R.id.item1_readtime);
			vh.sendtime=(TextView) arg1.findViewById(R.id.item1_sendtime);
			vh.category=(TextView) arg1.findViewById(R.id.item1_category);
			vh.img=(ImageView) arg1.findViewById(R.id.item1_image);
			vh.id=(TextView) arg1.findViewById(R.id.item1_id);
			arg1.setTag(vh);
		}else{
			vh=(ViewHolder) arg1.getTag();
		}
		News2 ne = data.get(arg0);
		vh.category.setText("分类："+ne.tag);
		vh.readtime.setText("浏览次数："+ne.count);
		vh.titel.setText(ne.title);
		
//		SimpleDateFormat simple=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//		String time = simple.format(Date数据);
		vh.sendtime.setText("发布时间："+ne.time);
		vh.id.setText(""+ne.id);
		Picasso.with(context).load("http://www.yi18.net/"+ne.img).into(vh.img);
		return arg1;
	}
	class ViewHolder{
		TextView titel;
		TextView sendtime;
		TextView category;
		TextView readtime;
		TextView id;
		ImageView img;
	}

}
